package com.etms.controller;

import com.etms.pojo.Customer;
import com.etms.pojo.Supplier;
import com.etms.pojo.WareHouse;
import com.etms.service.CangService;
import com.etms.service.CustomerService;
import com.etms.service.SupplierService;
import com.etms.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("utils")
public class UtilController {//getsulist
    @Autowired
    SupplierService supplierService;

    @GetMapping("getsulist")
    public Result getsulist(){
        return supplierService.findAll();
    }

    @GetMapping("getSuById/{id}")
    public Result getSuById(@PathVariable("id")Integer id){
        return supplierService.findSuById(id);
    }

    @GetMapping("delSuById/{id}")
    public Result delSuById(@PathVariable("id")Integer id){
        return supplierService.delSuById(id);
    }

    @PostMapping("suupdateOrAdd")
    public Result suupdateOrAdd(@RequestBody Supplier supplier){
        return supplierService.updateOrAdd(supplier);
    }

    @Autowired
    CustomerService customerService;

    @GetMapping("getculist")
    public Result getculist(){
        return customerService.findAll();
    }

    @GetMapping("getCuById/{id}")
    public Result getCuById(@PathVariable("id")Integer id){
        return customerService.findSuById(id);
    }

    @GetMapping("delCuById/{id}")
    public Result delCuById(@PathVariable("id")Integer id){
        return customerService.delSuById(id);
    }

    @PostMapping("cuupdateOrAdd")
    public Result cuupdateOrAdd(@RequestBody Customer customer){
        return customerService.updateOrAdd(customer);
    }


    @Autowired
    CangService cangService;
    @GetMapping("getwlist")
    public Result getwlist(){
        return cangService.findAll();
    }

    @GetMapping("getwById/{id}")
    public Result getwById(@PathVariable("id")Integer id){
        return cangService.findSuById(id);
    }

    @GetMapping("delwById/{id}")
    public Result delwById(@PathVariable("id")Integer id){
        return cangService.delSuById(id);
    }

    @PostMapping("wupdateOrAdd")
    public Result wupdateOrAdd(@RequestBody WareHouse wareHouse){
        return cangService.updateOrAdd(wareHouse);
    }
}
